package com.wwz.leetcode;
/**
 * <p>Description:字符串题目</p >
 * <p>Copyright: Copyright (c)2020</p >
 * <p>Company: Tope</p >
 * <P>Created Date :2020-06-04</P>
 * <P>@version 1.0</P>
 */
public class StringExercises {
    public static void main(String[] args) {
        String s = "We are happy.";
        String replaceSpace = replaceSpace(s);
        System.out.println(replaceSpace);

    }
    /**
    * @Description: 请实现一个函数，把字符串 s 中的每个空格替换成"%20"。
    * @create: 2020-06-04 22:11
    * @update logs
    * @throws Exception
    */
    // 或者直接replace
    public static String replaceSpace(String s) {
        StringBuffer sb=new StringBuffer();
        for(char c:s.toCharArray()){
            if(c ==' ')
                sb.append("%20");
            else
                sb.append(c);
        }
        return sb.toString();
    }
}
